<?php
include_once 'config.php';
include_once 'islogin.php';
include_once 'fun.php';
$_SESSION['isadmin'] = isset($_SESSION['isadmin']) ? $_SESSION['isadmin'] : '';
if ($_SESSION['isadmin'] != 0 && $_SESSION['isadmin'] != -1) {
    header('Refresh:1;url=shop.php');
    die("请以销售身份登录");
}
$name = isset($_POST['Name']) ? trim($_POST['Name']) : '';
$type = isset($_POST['type']) ? trim($_POST['type']) : 'CONVERT(Name using GBK)';
$order = isset($_POST['order']) ? trim($_POST['order']) : 'ASC';

if ($name) {
    $sql = "select * from product where Name like '%$name%' order by $type $order,CONVERT(Name using GBK) ASC ";
} else {
    $sql = "select * from product order by $type $order ,CONVERT(Name USING GBK) ASC ";
}

$con = connect();
$res = query($sql, $con);


$result3 = array();




while ($row = mysqli_fetch_all($res)) {
    $result3 = $row;
}

?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <title>报表查看</title>


</head>
<style>
    .delete {
        width: 80px;
        height: 30px;
    }

    .delete:hover {
        background: #333;
        color: white;
    }

    .edit:hover {
        background: #333;
        color: white;
    }

    .edit {
        width: 80px;
        height: 30px;


    }

    .load {
        text-decoration: none;
    }

    .loadDiv {
        height: 30px;
        width: 100px;
        position: absolute;
        top: 10px;
        left: 1200px;
        text-align: center;
        padding-top: 10px;
        background: #eee;
        border: #DCDC 2px solid;
        border-radius: 5px;
    }

    .loadDiv:hover {
        background-color: #E6E6FA;

        box-shadow: 0 8px 10px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
    }

    ._button {
        background-color: grey;
        border: none;
        padding: 10px;
        color: white;
        text-align: center;
        font-size: 10px;
        margin-top: 0px;
        margin-right: 50px;
        margin-left: 50px;
        cursor: pointer;
    }

    ._button:hover {
        transition: all 0.5s;
        background: #333;
        color: white;
    }

    .content {
        margin-top: 20px;
    }

    .init-loading-home {
        background-color: #303133;
        display: flex;
        flex-direction: column;

    }

    .init-loading-home {
        height: 5%;
        display: none;
        z-index: 1;
    }

    .init-loading-main {
        user-select: none;
        width: 100%;
        height: 20%;
        flex-grow: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        z-index: 1;
    }

    .init-loading-title {
        color: #FFF;
        font-size: 14px;
        margin-bottom: 10px;
    }

    .init-loading-sub-title {
        color: #ABABAB;
        font-size: 12px;
    }

    .init-loading-footer {
        width: 100%;
        height: 20%;
        flex-grow: 0;
        text-align: center;
        padding: 1em 0;
    }

    .loader-first {
        font-size: 10px;
        margin: 100px auto;
        width: 1em;
        height: 1em;
        border-radius: 50%;
        text-indent: -9999em;
        position: relative;
        animation: mymove 1.3s infinite linear;
        -webkit-animation: mymove 1.5s infinite linear;
        -webkit-transform: translateZ(0);
        -ms-transform: translateZ(0);
        transform: translateZ(0);
    }

    .buttontwo {
        margin-top: 15px;
    }

    .editblock {
        width: 300px;
        height: 400px;
        text-align: center;
        margin-left: 25%;
        margin-top: -100px;
        z-index: 1;
        border-radius: 10px;
        /* left: calc(100%-50px); */
        position: absolute;
    }

    .editblock .contenti {
        position: absolute;
        left: calc(50% - 210px);
        width: 300px;
        height: 350px;
    }

    .contenti {
        background: #eee;
        border-radius: 10px;
    }

    .contenti .title .editblock {

        display: flex;
        justify-content: space-between;
        /* 鼠标移入呈现移动光标 */
        cursor: move;

    }

    .customers {
        font-family: Arial, Helvetica, sans-serif;
        border-collapse: collapse;
        width: 70%;
        margin-top: 30px;
    }

    .customers td,
    .customers th {
        border: 1px solid #ddd;
        padding: 8px;
    }

    .customers tr:nth-child(even) {
        background-color: #f2f2f2;
    }

    .customers tr:hover {
        background-color: #ddd;
    }

    .customers th {
        padding-top: 12px;
        padding-bottom: 12px;
        text-align: left;
        background-color: #333;
        color: white;
    }

    input[type=text1] {
        width: 40%;
        box-sizing: border-box;
        border: 2px solid #ccc;
        border-radius: 4px;
        font-size: 16px;
        background-image: url('../网页图片/搜索\ \(1\).png');
        background-color: white;
        background-position: 10px 10px;
        background-repeat: no-repeat;
        padding: 12px 20px 12px 50px;
        margin-left: 400px;
    }

    input[type=text2],
    [type=number2] {
        width: 80%;
        padding: 12px 20px;
        margin: 8px 0;
        display: inline-block;
        border: 1px solid #ccc;
        border-radius: 4px;
        box-sizing: border-box;
    }

    .search_btn {
        margin-left: 10px;
        height: 45px;
        width: 60px;
    }

    .add_blocki {
        width: 25%;
        height: 40%;
        background-color: #f1f1f1;
        margin-left: 75%;
        position: fixed;
        text-align: center;
        margin-top: -200px;
    }

    .add_block {
        width: 25%;
        height: 40%;
        background-color: #f1f1f1;
        margin-left: 75%;
        position: fixed;
        text-align: center;
        margin-top: -200px;
    }

    .top_add {
        background-color: #333;
        height: 40px;
        color: white;
        font-size: x-large;
        margin-top: 0px;
        font-weight: bold;
    }

    .body {
        overflow-y: scroll;
    }

    .deletei {
        color: black;
    }

    .deletei:hover {
        color: white;
    }

    .title {
        background: #333;
        color: white;
        font-size: 20px;
        font-weight: 700;
        height: 40px;
        text-align: center;
        padding-top: 8px;
        border-top-left-radius: 10px;
        border-top-right-radius: 10px;
        cursor: move;

        /* left: calc(100%-50px); */
    }

    .admini {
        background: #eee;
        height: 30px;
        width: 100px;
        margin-top: -40px;
        border: #DCDCDC 2px solid;
        border-radius: 5px;
        text-align: center;
        padding-top: 5px;

    }

    .admini:hover {
        background-color: #E6E6FA;
        color: white;
        box-shadow: 0 8px 10px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
    }

    .logouti {
        background: #eee;
        width: 100px;
        height: 30px;
        margin-left: 200px;
        margin-top: -38px;
        border: #DCDCDC 2px solid;
        border-radius: 5px;
        text-align: center;
        padding-top: 5px;
    }

    .logouti:hover {
        background-color: #E6E6FA;
        color: white;
        box-shadow: 0 8px 10px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
    }

    .sss {
        background-color: #333;
        border-style: hidden;
        cursor: pointer;
    }
</style>

<body>
    <form action="report.php" method="POST">
        <input type="text1" name="Name" placeholder="搜索...">
        <button class="search_btn" onclick="formSubmit()">查询</button>
    </form>
    <div class="admini">
        <a href="admin_detail.php" style="text-decoration: none;"><i class="fa fa-user-circle"></i><?php echo $_SESSION['username']; ?></a>
    </div>
    <div class="logouti">
        <a href="logout.php" style="text-decoration: none;" onclick="return confirm('确定退出吗？');"><i class="fa fa-sign-out"></i>退出登录</a>
    </div>

    <table class="customers">
        <thead>
            <tr>
                <th>序号</th>
                <th>商品名称</th>

                <th>销售价格

                    <form action="report.php" method="POST">
                        <button class="sss" onclick="formSubmit()">
                            <i class="fa fa-chevron-up " style="color:white"></i>
                        </button>
                        <input type="hidden" name="type" value="price">
                        <input type="hidden" name="order" value='ASC'>
                        <input type="hidden" name='Name' value=<?php echo $name; ?>>
                    </form>
                    <form action="report.php" method="POST">
                        <input type="hidden" name="type" value="price">
                        <input type="hidden" name="order" value='DESC'>
                        <input type="hidden" name='Name' value=<?php echo $name; ?>>
                        <button class="sss" onclick="formSubmit()">
                            <i class="fa fa-chevron-down " style="color:white"></i>
                        </button>
                    </form>
                </th>
                <th>销量

                    <form action="report.php" method="POST">
                        <button class="sss" onclick="formSubmit()">
                            <i class="fa fa-chevron-up " style="color:white"></i>
                        </button>
                        <input type="hidden" name="type" value="soldnum">
                        <input type="hidden" name="order" value='ASC'>
                        <input type="hidden" name='Name' value=<?php echo $name; ?>>
                    </form>
                    <form action="report.php" method="POST">
                        <input type="hidden" name="type" value="soldnum">
                        <input type="hidden" name="order" value='DESC'>
                        <input type="hidden" name='Name' value=<?php echo $name; ?>>
                        <button class="sss" onclick="formSubmit()">
                            <i class="fa fa-chevron-down " style="color:white"></i>
                        </button>
                    </form>
                </th>
                <th>成本
                    <form action="report.php" method="POST">
                        <button class="sss" onclick="formSubmit()">
                            <i class="fa fa-chevron-up " style="color:white"></i>
                        </button>
                        <input type="hidden" name="type" value="costoverall">
                        <input type="hidden" name="order" value='ASC'>
                        <input type="hidden" name='Name' value=<?php echo $name; ?>>
                    </form>
                    <form action="report.php" method="POST">
                        <input type="hidden" name="type" value="costoverall">
                        <input type="hidden" name="order" value='DESC'>
                        <input type="hidden" name='Name' value=<?php echo $name; ?>>
                        <button class="sss" onclick="formSubmit()">
                            <i class="fa fa-chevron-down " style="color:white"></i>
                        </button>
                    </form>
                </th>
                <th>利润

                    <form action="report.php" method="POST">
                        <button class="sss" onclick="formSubmit()">
                            <i class="fa fa-chevron-up " style="color:white"></i>
                        </button>
                        <input type="hidden" name="type" value="incomeoverall-costoverall">
                        <input type="hidden" name="order" value='ASC'>
                        <input type="hidden" name='Name' value=<?php echo $name; ?>>
                    </form>
                    <form action="report.php" method="POST">
                        <input type="hidden" name="type" value="incomeoverall-costoverall">
                        <input type="hidden" name="order" value='DESC'>
                        <input type="hidden" name='Name' value=<?php echo $name; ?>>
                        <button class="sss" onclick="formSubmit()">
                            <i class="fa fa-chevron-down " style="color:white"></i>
                        </button>
                    </form>
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <?php foreach ($result3 as $k => $res) : ?>
                    <td><?php echo $k + 1; ?></td>
                    <td><?php echo $res[1]; ?></td>
                    <td><?php echo $res[2]; ?></td>
                    <td><?php echo $res[5]; ?></td>
                    <td><?php echo $res[6]; ?></td>
                    <td><?php echo $res[7] - $res[6]; ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
    <div class="sortlist">
    </div>
    <div class="loadDiv">
        <a href="reportdownload.php?Name=<?php echo $name; ?>&type=<?php echo $type; ?>&order=<?php echo $order; ?>" class="load">
            下载
        </a>
    </div>
    <script>


    </script>

</body>

</html>